package com.testfileupload.uploadimg.design.visitor;

public class Visitor implements IVisitor {
    @Override
    public void visit(CommonEmployee commonEmployee) {
        System.out.println(this.getCommonEmployee(commonEmployee));
        int salary = commonEmployee.getSalary();
        calCommonTotalSalary(salary);
    }

    private String getCommonEmployee(CommonEmployee commonEmployee) {
        String basicInfo = this.getBasicInfo(commonEmployee);
        String otherInfo = "工作：" + commonEmployee.getJob();
        return basicInfo + otherInfo;
    }

    private String getBasicInfo(Employee employee) {
        String info = "姓名：" + employee.getName();
        info = info + "性别" + (employee.getSex() == Employee.FEMALE ? "女" : "男");
        info = info + "薪水" + employee.getSalary();
        return info;
    }

    @Override
    public void visit(Manager manager) {
        System.out.println(this.getManagerInfo(manager));
        int salary = manager.getSalary();
        calManagerTotalSalary(salary);
    }

    //部门经理工资系数
    private final static int MANAGER_COFEEIIENT = 5;
    //员工系数为2
    private final static int COMMONEMPLOYEE_COFEEIIENT = 2;
    //普通员工的工资和
    private int commonTotalSalary = 0;
    private int managerTotalSalary = 0;

    private void calCommonTotalSalary(int salary) {
        this.commonTotalSalary = this.commonTotalSalary + salary * COMMONEMPLOYEE_COFEEIIENT;
    }

    private void calManagerTotalSalary(int salary) {
        this.managerTotalSalary = this.managerTotalSalary + salary * MANAGER_COFEEIIENT;
    }

    @Override
    public int getTotalSalary() {
        return this.managerTotalSalary + this.commonTotalSalary;
    }

    private String getManagerInfo(Manager manager) {
        String basicInfo = this.getBasicInfo(manager);
        String otherInfo = "业绩：" + manager.getPerformance();
        return basicInfo + otherInfo;
    }
}
